﻿@model QuanLyGiaoVuUI.Models.ThongBao.ThongBaoViewModel

@{
    ViewBag.Title = "ChiTietThongBaoGiangVien";
    Layout = "~/Views/Shared/_GiangVienClientLayout.cshtml";
}

<style>
    .titlethongbao {
        font-weight: bold;
        margin-right: 20px;
    }

    .hidden {
        display: none;
    }

    tr.fileDinhKem {
        line-height: 32px;
    }

        tr.fileDinhKem span {
            line-height: 32px;
        }
        tr.fileDinhKem td {
            min-width: 200px;
        }
</style>
<div class="grid_12">
    <div class="box round first grid">
    <h2>CHI TIẾT THÔNG BÁO</h2>
    <div class="block" style="width: 80%; margin: 20px auto;">
        @if (Model != null)
        {
            <div>
                <span class="titlethongbao">Tiêu Đề:</span>
                <span>@Model.TieuDeThongBao (<span style="font-style: italic; color: gray;">Đã gửi vào: @Model.NgayGuiThongBao</span>)</span>
            </div>
                        <div>
                <div class="titlethongbao">Người gửi:</div>
                <div>@Model.NguoiGui.HoTenGV (@Model.NguoiGui.Email)</div>
            </div>
            <div>
                <div class="titlethongbao">Nội Dung:</div>
                <div>@Model.NoiDungThongBao</div>
            </div>
            <div id="taiLieuDinhKem">
                @if (Model.DanhSachTaiLieuDinhKem.Count > 0)
                {
                    <div class="titlethongbao">Tài liệu đính kèm:</div>
                                 <table>
                            @foreach (QuanLyGiaoVuDAL.DTO.TaiLieuDTO taiLieu in Model.DanhSachTaiLieuDinhKem)
                            {
                                <tr class="fileDinhKem">
                                    <td>
                                        <input type="hidden" value="@taiLieu.MaTaiLieu" />
                                        <img src="@Url.Content("~/Content/themes/bluewhale/img/document_icon.png")" style="width: 32px; height: 32px; float: left" />
                                        <span>@taiLieu.TenTaiLieu</span>
                                    </td>
                                    <td class="rowAction">
                                        <input type="button" value="Xem" class="XemTaiLieu" />
                                        <input type="button" value="Sao chép" class="SaoChep" />
                                    </td>
                                </tr>
                            }
                        </table>
                }
            </div>
        }
    </div>
    </div>
</div>
<div id="xemTaiLieuDialog">
</div>
<div id="chonThuMucDialog"></div>

<script>
    $(document).ready(function () {
        $(".rowAction").addClass("hidden");

        $(".fileDinhKem").bind("mouseenter", function () {
            $(".rowAction").each(function () {
                if (!$(this).hasClass("hidden")) {
                    $(this).addClass("hidden");
                }
            });
            $(this).find(".rowAction").removeClass("hidden");
        });

        $(".fileDinhKem").bind("mouseleave", function () {
            $(".rowAction").addClass("hidden");
        });


        $(".XemTaiLieu").bind("click", function () {
            var taiLieuId = $(this).parent().parent().find("input[type=hidden]").first().val();
            $("#xemTaiLieuDialog").load("/TaiLieu/XemTaiLieu?maTaiLieu=" + taiLieuId).dialog({
                autoOpen: true,
                modal: true,
                width: 400,
                height: 400,
                title: "Xem nội dung tài liệu",
                buttons: {
                    "Đóng": function () {
                        $("#xemTaiLieuDialog").dialog("close");
                    }
                }
            });
        });

        $(".SaoChep").bind("click", function () {
            var taiLieuId = $(this).parent().parent().find("input[type=hidden]").first().val();
            $("#chonThuMucDialog").load("/TaiLieuGiangVien/ChonThuMucDialog").dialog({
                autoOpen: true,
                modal: true,
                width: 400,
                height: 400,
                title: "Chọn thư mục lưu tài liệu",
                buttons: {
                    "Sao chép": function () {
                        if (ChonThuMucDialog)
                        {
                            $.ajax({
                                url: "/TaiLieuGiangVien/SaoChepTaiLieu",
                                type: "POST",
                                data: {
                                    maTaiLieu: taiLieuId,
                                    maThuMuc: ChonThuMucDialog.MaThuMuc
                                },
                                success: function(data){
                                    if (data.success)
                                    {
                                        ToastManager.showSuccessToast("Sao chép tài liệu thành công.");
                                    }
                                    else
                                    {
                                        ToastManager.showStickyWarningToast(data.message);
                                    }
                                    $("#chonThuMucDialog").dialog("close");
                                }
                            });
                        }
                    },
                    "Đóng": function () {
                        $("#chonThuMucDialog").dialog("close");
                    }
                }
            });
        });
    });
</script>
